package com.qingxin.sys.verifier;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 验证项，可以为一个表单项、一个字段或某一特定类型的验证
 * @author JiWangli
 */
public abstract class VerifyItem {
	
	protected boolean foreground;
	protected boolean background;
	protected List<VerifyRule> rules;
	
	private Form form;

	
	public VerifyItem() {
		this.foreground = true;
		this.background = true;
		this.rules = new ArrayList<VerifyRule>();
	}
	
	
	/**
	 * 验证该项的有效性
	 * 
	 * @param formMsg
	 * @param formMap
	 * @return
	 */
	public abstract boolean verify(FormMsg formMsg, FormMap formMap);
	
	
	
	/**
	 * 获取该项的前台验证配置，如果不支持前台验证返回null
	 * 
	 * @return
	 */
	public abstract Map<String, Object> getItemCfg();
	
	
	/**
	 * 返回该验证项的名称
	 * 
	 * @return
	 */
	public abstract String getName();
	
	
	public boolean isForeground() {
		return foreground;
	}
	public void setForeground(boolean foreground) {
		this.foreground = foreground;
	}
	public boolean isBackground() {
		return background;
	}
	public void setBackground(boolean background) {
		this.background = background;
	}
	
	public List<VerifyRule> getRules() {
		return rules;
	}
	public void setRules(List<VerifyRule> rules) {
		this.rules = rules;
	}
	public void addRule(VerifyRule rule) {
		rule.setVerifyItem(this);
		rules.add(rule);
	}


	public Form getForm() {
		return form;
	}
	public void setForm(Form form) {
		this.form = form;
	}
	
	
}
